
package com.x52im.rbchat.logic.more;

import android.content.Intent;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.eva.android.widget.ActivityRoot;
import com.x52im.rbchat.Const;
import com.x52im.rbchat.R;
import com.x52im.rbchat.logic.main.loginimpl.LoginHelper;
import com.x52im.rbchat.logic.sns_friend.SendMailActivity;
import com.x52im.rbchat.utils.IntentFactory;
import com.x52im.rbchat.utils.ToolKits;

public class AboutActivity extends ActivityRoot
{
	// 条款
	private Button termsBtn = null;
	// 隐私
	private Button privacyBtn = null;
	
	// officalwebsite
	private Button websiteBtn = null;
	// mail
	private Button mailBtn = null;
	
	//----------------------------------- SNS1
	// facebook
	private Button facebookBtn = null;
	// twitter
	private Button twitterBtn = null;
	// tumblr
	private Button tumblrBtn = null;

	private TextView versionView = null;

	/**
	 * 本方法由父类的 {@link #init(Bundle)} 调用，子类可在此方法中实现ui的初始化。
	 */
	@Override
	protected void initViews(Bundle savedInstanceState)
	{
		// 设定自定义标题栏（设定此值即意味着开启自定义标题栏的使用，必须要在setContentView前设定）
		customeTitleBarResId = R.id.main_about_titleBar;
		// 养成良好习惯：首先设置主layout，确保后绪的操作中使用到的组件都可以被find到
		setContentView(R.layout.main_about);

		termsBtn = (Button) findViewById(R.id.main_about_terms_conditions);
		privacyBtn = (Button) findViewById(R.id.main_about_privacy_policy);
		facebookBtn = (Button) findViewById(R.id.main_about_facebook);
		twitterBtn = (Button) findViewById(R.id.main_about_twitter);
		tumblrBtn = (Button) findViewById(R.id.main_about_tumblr);
		websiteBtn = (Button) findViewById(R.id.main_about_official_website);
		mailBtn = (Button) findViewById(R.id.main_about_mail);
		versionView = (TextView) findViewById(R.id.main_about_versionView);
		
		// APP版本信息
		versionView.setText(LoginHelper.getAPKVersionName() + "(" + LoginHelper.getAPKVersionCode() + ")");
		
		// 设置标题（自定义标题栏后的title文本设置是不同的哦，见CustomeTitleBar中的说明）
		this.setTitle(R.string.main_about_title);
	}

	/**
	 * 本方法由父类的 {@link #init(Bundle)} 调用，子类可在此方法中为各UI功能组件增加事件临听。
	 */
	@Override
	protected void initListeners()
	{
		mailBtn.setOnClickListener(v -> startActivity(new Intent(AboutActivity.this, SendMailActivity.class)));

		termsBtn.setOnClickListener(v -> startWebAcvitity(ToolKits.isChinese_SimplifiedChinese()?Const.RBCHAT_REGISTER_AGREEMENT_CN_URL
				: Const.RBCHAT_REGISTER_AGREEMENT_EN_URL
		, $$(R.string.main_about_terms_conditions), true));

		privacyBtn.setOnClickListener(v -> startWebAcvitity(ToolKits.isChinese_SimplifiedChinese()?Const.RBCHAT_PRIVACY_CN_URL:Const.RBCHAT_PRIVACY_EN_URL
		, $$(R.string.main_about_privacy_policy), true));

		websiteBtn.setOnClickListener(v -> startWebAcvitity(Const.RBCHAT_OFFICAL_WEBSITE, $$(R.string.main_about_official_website), false));

		OnClickListener shareOnClickListener = v -> {
			Intent it = new Intent(Intent.ACTION_SEND);
			it.putExtra(Intent.EXTRA_TEXT, "The email subject text");
			it.setType("text/plain");
			startActivity(Intent.createChooser(it, "Choose Share Client"));
		};
		facebookBtn.setOnClickListener(shareOnClickListener);
		twitterBtn.setOnClickListener(shareOnClickListener);
		tumblrBtn.setOnClickListener(shareOnClickListener);
	}

	private void startWebAcvitity(String url, String title, boolean forSafe)
	{
		startActivity(IntentFactory.createCommonWebActivity2Intent(AboutActivity.this, url, title, forSafe));
	}
}
